package com.masterclient.app.businessmodule.minemodule.point.contract;

import com.eoner.common.config.Config;
import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.managerlibrary.netsign.NetEnvManager;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.masterclient.app.businessmodule.minemodule.point.model.PointExchangeBean;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class PointExchangeContractPresenter extends PointExchangeContract.Presenter {


    @Override
    public void getPointExchangeData(String page, String page_size) {

        String url = NetEnvManager.BASE_SURL+"api/customer/integral_order?version=" + Config.URL_VERSION;

        Observable<PointExchangeBean> observable = RetrofitUtil.getInstance().getPointExchange(url,page,page_size);

        Disposable disposable = toSubscribe(observable, new Consumer<PointExchangeBean>() {
            @Override
            public void accept(@NonNull PointExchangeBean bean) throws Exception {

                if("0".equals(bean.getCode())){
                    mView.showData(bean);
                }else {
                    mView.loadFail(bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.loadFail("网络异常，请重试");
            }
        });
        mRxManager.add(disposable);

    }
}
